package com.lemon.ai.socket.packets.spiritgame.model.generator;

import java.util.List;

import com.lemon.ai.socket.packets.spiritgame.model.dto.Column;
import com.lemon.ai.socket.packets.spiritgame.model.dto.Table;
import com.lemon.ai.socket.packets.spiritgame.model.generator.utils.StringUtils;

public class MappingFileGenerator extends AbstractGenerator {

	public MappingFileGenerator() {
		super("MappingClassTemp.txt");
	}

	public String generateClassName() {
		return super.prop.getProperty("dir")
				+ super.prop.getProperty("package").replace(".", "\\")
				+ "\\utils\\" + "Mapping.java";
	}

	public String generate(List<Table> tables) {
		StringBuilder sb = new StringBuilder();
		StringBuilder cs = new StringBuilder();

		for (Table t : tables) {
			sb.append("table2class.put(\"" + t.getName()+ "\", \"" + StringUtils.generateClassName(t.getName()) + "\");\r\t\t");
			sb.append("class2table.put(\"" + StringUtils.generateClassName(t.getName())+ "\", \"" + t.getName() + "\");\r\t\t");
			cs.append("columns.put(\"" + t.getName()+ "\", new HashSet<String>());\r\t\t");
			for (Column c : t.getColumns()) {
				cs.append("columns.get(\"" + t.getName()+ "\").add(\""+ c.getName() + "\");\r\t\t");
			}
		}
		
		
		
		return super.temp.
				replaceAll("SETS_CLASSS_TABLES", sb.toString()).
				replaceAll("PACKAGE_NAME", super.prop.getProperty("package")).
				replaceAll("SETS_TABLE_COLUMNS", cs.toString())
				
				;
	}

}
